
package com.yishe.config;


import com.yishe.constant.WebConstant;
import com.yishe.intercepter.UserAuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * create by: chusifeng
 * Create in 2021/4/9 9:57
 * Description:拦截器和全局配置
 * <p>Example</p>
 */
@Configuration
@Primary
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 1.用户授权拦截
        registry.addInterceptor(getUserAuthInterceptor())
                .excludePathPatterns(WebConstant.EXCLUDE_LOGIN)
                .excludePathPatterns(WebConstant.EXCLUDE_ERROR)
                .excludePathPatterns(WebConstant.EXCLUDE_WXCORE)
                .excludePathPatterns(WebConstant.EXCLUDE_WX);

        WebMvcConfigurer.super.addInterceptors(registry);
    }

    /**
     * 配置用户用户信息拦截
     *
     * @return
     */
    @Bean
    UserAuthInterceptor getUserAuthInterceptor() {
        return new UserAuthInterceptor();
    }
}
